home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Input / IFOParser / misc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-06  |  2.6 KB  |  119 lines

  1.  
  2. /*
  3.  *
  4.  * Copyright (C) 1998,1999  Thomas Mirlacher
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  * 
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  * 
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  * 
  20.  * The author may be reached as dent@cosy.sbg.ac.at, or
  21.  * Thomas Mirlacher, Jakob-Haringerstr. 2, A-5020 Salzburg,
  22.  * Austria
  23.  *
  24.  *------------------------------------------------------------
  25.  *
  26.  */
  27.  
  28.  
  29. #include <stdio.h>
  30. #include <io.h>
  31.  
  32. #include <sys/types.h>
  33. //#include <unistd.h>
  34. #include <stdlib.h>
  35.  
  36. #include "ifo.h"
  37. #include "misc.h"
  38.  
  39.  u_int  get4bytes (u_char *buf)
  40. {
  41.     return bswap_32 (*((u_int32_t *)buf));
  42. }
  43.  
  44. u_int get2bytes (u_char *buf)
  45. {
  46.     return bswap_16 (*((u_int16_t *)buf));
  47. }
  48.  
  49. int ifoReadTBL (ifo_t *ifo, u_int offset, u_int tbl_id)
  50. {
  51.     u_char *data;
  52.     u_int len = 0;
  53.  
  54.     if (!offset)
  55.         return -1;
  56.  
  57.     if (!(data =  (u_char *) malloc (DVD_VIDEO_LB_LEN))) {
  58.         perror ("malloc");
  59.         return -1; 
  60.     }
  61.  
  62.     if (ifoReadLB (ifo->fd, ifo->pos + offset * DVD_VIDEO_LB_LEN, DVD_VIDEO_LB_LEN, data) <= 0) {
  63.         perror ("ifoReadLB");
  64.         return -1;
  65.     }
  66.  
  67.     switch (tbl_id) {
  68.         case ID_TITLE_VOBU_ADDR_MAP:
  69.         case ID_MENU_VOBU_ADDR_MAP:
  70.             len = get4bytes (data) + 1;
  71.             break;
  72.  
  73.         default: {
  74.             ifo_hdr_t *hdr = (ifo_hdr_t *) data;
  75.             len = bswap_32 (hdr->len) + 1;
  76.         }
  77.     }
  78.  
  79.     if (len > DVD_VIDEO_LB_LEN) {
  80.         if (!(data =  (u_char *) realloc ((void *) data, len))) {
  81.             perror ("realloc");
  82.             return -1; 
  83.         }
  84.  
  85.         ifoReadLB (ifo->fd, ifo->pos + offset * DVD_VIDEO_LB_LEN, len, data);
  86.     }
  87.  
  88.     ifo->data [tbl_id] = data;
  89.  
  90. {    int i;
  91.     u_int32_t *ptr = (u_int32_t *)data;
  92.  
  93.     len/=4;
  94.  
  95.     if (tbl_id == ID_TMT) 
  96.         for (i=0; i<len; i++)
  97.             ptr[i] = bswap_32 (ptr[i]);
  98.         
  99. }
  100.  
  101.     return 0;
  102. }
  103.  
  104.  
  105. /**
  106.  *
  107.  */
  108.  
  109. int ifoReadLB (int fd, __off64_t pos, u_int count, u_char *data)
  110. {
  111.     if ((pos = _lseeki64 (fd, pos, SEEK_SET)) == -1) {
  112.                 fprintf (stderr, "%s/%d: error in lseek (pos: 0x%x)\n",
  113.                         __FILE__, __LINE__, pos);
  114.                 return -1;
  115.         }
  116.  
  117.     return read (fd, data, count); 
  118. }
  119.